<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\facade\Basic;
use app\admin\service\SellerProduct as ServiceSellerProduct;
use think\Request;

/**
 *  供应商/零售商
 */
class SellerProduct extends BaseController
{

    /**
     *   获取枚举
     */
    public function resource(Request $request)
    {
        $param['field'] = $request->param('field');
        $SellerProduct = new ServiceSellerProduct();
        $result = $SellerProduct->getEnum($param);
        return Basic::json($result);
    }


    /**
     *  供应商/零售商
     */
    public function getList(Request $request)
    {


        $param['pageIndex'] = $request->param('pageIndex',1);
        $param['pageSize'] = $request->param('pageSize',50);

        $param['category'] = $request->param('category',1);
        $param['seller_id'] = $request->param('seller_id',null);
        $param['model_id'] = $request->param('model_id',null);
        $param['product_name'] = $request->param('product_name',null);
        $param['status'] = $request->param('status',null);

        /* 验证 */
        //$this->validateData($param,'SellerProduct.getList');

        $SellerProduct = new ServiceSellerProduct();
        $result = $SellerProduct->getList($param);
        return Basic::json($result);
    }


    /**
     *  商品状态状态更新
     */
    public function status(Request $request)
    {
        $param['updater'] = $request->operator_id;
        $param['ids'] = $request->param('ids',[]);
        $param['status'] = $request->param('status',1);

        /* 验证 */
        //$this->validateData($param,'SellerProduct.getList');

        $SellerProduct = new ServiceSellerProduct();
        $result = $SellerProduct->status($param);
        return Basic::json($result);
    }

    /**
     *  获取详情
    */
    public function detail(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        /* 验证 */
        $this->validateData($param,'Seller.detail');

        $SellerProduct = new ServiceSellerProduct();
        $result = $SellerProduct->detail($param);
        return Basic::json($result);
    }

    /**
     *  修改机型
    */
    public function update(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $param['seller_id'] = $request->param('seller_id',null);
        $param['model_id'] = $request->param('model_id',null);
        $param['product_name'] = $request->param('product_name',null);
        $param['product_detail_url'] = $request->param('product_detail_url',null);
        $param['status'] = $request->param('status',1);
        $param['product_name']  = trim($param['product_name']);
        /* 验证 */
       // $this->validateData($param,'ModelInfo.update');

        $SellerProduct = new ServiceSellerProduct();
        $result = $SellerProduct->update($param);
        return Basic::json($result);
   }

    /**
     *  删除机型
    */
    public function delete(Request $request)
    {
        $param['updater'] = $request->operator_id;
        $param['ids'] = $request->param('ids',null);

        /* 验证 */
        //$this->validateData($param,'ModelInfo.delete');

        $SellerProduct = new ServiceSellerProduct();
        $result = $SellerProduct->delete($param);
        return Basic::json($result);
    }



}
